package com.fastwire.carriere.service;

import java.util.List;

import javax.jws.WebService;

import com.fastwire.carriere.common.Messages;
import com.fastwire.carriere.common.util.ResourceUtil;
import com.fastwire.carriere.controller.ControllerProxy;
import com.fastwire.carriere.controller.SystemAdminController;
import com.fastwire.carriere.controller.impl.SystemAdminControllerImpl;
import com.fastwire.carriere.service.webui.exception.ServiceException;
import com.fastwire.carriere.system.vo.SystemParameterVo;
import com.fastwire.carriere.user.vo.SessionVo;

@WebService(endpointInterface = "com.fastwire.carriere.service.SystemAdminService")
public class SystemAdminServiceImpl implements SystemAdminService {

	@Override
	public List<SystemParameterVo> getSystemParametersbyCatelog(String catelog,
			SessionVo sessionVo) throws ServiceException {

		try {
			SystemAdminController controller = (SystemAdminController) ResourceUtil
					.getSessionBindClassByName(
							SystemAdminControllerImpl.class.getName(),
							sessionVo, true);
			List<SystemParameterVo> parameterVos = controller
					.getSystemParametersbyCatelog(catelog);
			return parameterVos;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

			String ex = ControllerProxy.getRootException(e);
			throw new ServiceException(ex);

		}
	}

	@Override
	public String updateSystemParameter(SystemParameterVo parameterVo,
			SessionVo sessionVo) throws ServiceException {
		String msg = Messages.getString("message.common.service.success");

		try {
			SystemAdminController controller = (SystemAdminController) ResourceUtil
					.getSessionBindClassByName(
							SystemAdminControllerImpl.class.getName(),
							sessionVo, true);
			parameterVo.setUpdatedby(sessionVo.getUserName());
			controller.updateSystemParameter(parameterVo);
			return msg;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

			String ex = ControllerProxy.getRootException(e);
			throw new ServiceException(ex);

		}
	}

}
